<?php

class UsersController extends AppController {
    
    public $name = "Users";
    public $helpers = array("Html", "Form", "Session");
    
    public function index() {
        $this->redirect("login");
    }
    
    public function login() {
        if (!empty($this->request->data)) {
            if (($user = $this->User->check_login($this->request->data))) {
                $this->Session->write("User", $user);
                $this->Session->setFlash("You have successfully logged in");
                $this->redirect(array("controller" => "formats", "action" => "index", "admin" => true));
            } else {
                $this->set("error", "ERROR: Invalid Username or Password.");
            }
        }
    }
    
    public function logout() {
        $this->Session->delete("User");
        $this->Session->setFlash("You have successfully logged out");
        $this->redirect(array("action" => "login", "controller" => "users"));
    }
}

?>